Global Lua Modules/Colors
Colors is a library for embedded color processing in the Fandom environment. It ports and extends functionality from the Colors JavaScript library from Pecoes. Features * Color parameter support in Lua modules * Color parameter insertion in wiki templates * Color variable parsing for style templating * Color item creation and conversion utilities * A vast array of color processing methods * Alpha and boolean support for flexible color logic Demo This demo uses to render the color scheme. |#}} | Light Gray | the body | color-body | |#}} | White | the page | color-page | |#}} | Mid Dark Gray | the header | color-header | |#}} | Cerulean | links | color-links | |#}} | Mid Dark Gray | buttons | color-buttons }} How to install There are two components you can install: Module The module itself can be invoked globally with the following code: local colors = require('Dev:Colors') Template Variables stylesheet To install the CSS variables stylesheet: Add the following text to your sandbox: }} Copy the contents of the code block to MediaWiki:Variables.css. Then follow these CSS installation instructions: If you would prefer automatic updates (despite lower server-side efficiency, & potential security implications), you can use the following instructions. Add this import to your sitewide CSS: @import url("/index.php?title=MediaWiki:Variables.css&action=raw&templates=expand&ctype=text/css"); | collapse = 1 | padding = 1em }} Usage Example usage on a wiki Rendered output on desktop: Example usage in a Lua module local colors = require("Dev:Colors") mw.log(colors.fromHsl(214, 0.15, 0.8):string()) -- expected output '#414b58' Package members and methods The following keys are exposed in the module package: Template utilites ;colors.wikia :Simple color parameter getter (list). :This returns a color from the parameter table. :Usage: ;colors.css :Color parameter parser for inline styling. :Usage: ;colors.text :Color generator for high-contrast text. :Accounts for luminance when |lum=true. :Usage: ;colors.variables :CSS variables stylesheet generator. :Arguments: s - optional whitespace flag. :Usage: Other library methods ;colors.instance :Color instance test for Lua modules. :Usage: colors.instance('#ffffff') ;colors.params :Table of Fandom SASS colors for Lua modules (list). :Usage: colors.paramsstring_key Color item creation There are three ways to construct a new color in your Lua module: ;colors.fromRgb :Color instance creation from RGB tuple. :Fourth argument is optional alpha value (0-1). :Usage: colors.fromRgb(255, 255, 255, 0.2) ;colors.fromHsl :Color instance creation from HSL tuple. :Fourth argument is optional alpha value (0-1). :Usage: colors.fromHsl(0, 0, 1, 0.2) ;colors.parse :Color parsing of any valid CSS color string. :Usage: colors.parse('#ffffff') Color parameters There are 23 parameters supported in the library. Request more in the talkpage. These can be accessed in three ways: * colors.params table in your Lua module * colors.wikia template method * $parameter syntax in colors.css, colors.text and colors.parse Color items and methods A newly constructed Color instance will store certain color data: local color = colors.parse('cyan') -- {table} color.tup Color tuple mw.log(unpack(color.tup)) -- '0 255 255' -- {string} color.typ Color type mw.log(color.tup) -- 'rgb' -- {string} color.alp Color alpha channel mw.log(color.alp) -- 1 Some color methods are also available. Property getter-setter methods These methods retrieve or override color properties. (*''' = optional) Processing methods These methods are for post-processing color operations. (*''' = optional) Conditionals for color logic These methods return a boolean for use in Lua logic. (* = optional) Output methods These methods return a valid CSS color string.